<?php

namespace App\Console\Commands;


use App\Services\Classes\Youzan as YouzanRaw;
use App\Services\Facades\Youzan;
use App\Services\Models\Orders;
use Illuminate\Console\Command;

    

/**
 * DayTotal
 * 
 */
class UpdateReportStatus extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'update:report';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     * 
     * @return mixed
     */
    public function handle()
    {
        $orders = Orders::where('customs_status','>=',1)->get();
        foreach($orders as $order){
            $params = [
                'kdt_id' => YouzanRaw::kdt_id,
                'transaction' => $order->transaction, 
                'tid' => $order['tid'],
            ];
            $response = Youzan::updateReportStatus($params);
            $order->customs_status = $response['data']['customs_status'];
            $order->report_query_response = json_encode($response);
            $order->save();
        }
    }
}